package tmall.common.service;

import cn.dev33.satoken.stp.StpInterface;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Component;
import tmall.common.config.AppConst;
import tmall.domain.entity.User;
import tmall.domain.service.UserService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zhangservlet
 * @description: Sa-token 自定义鉴权
 * @date 2021/7/9
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Resource
    private UserService userService;

    /**
     * 获取用户权限集合
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return null;
    }

    /**
     * 获取用户角色集合
     * @param loginId
     * @param loginType
     * @return
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<String> roles = Lists.newArrayList();
        Map<String, Object> params = Maps.newHashMap();
        params.put("id", loginId);
        User user = userService.findBy(params);
        if(AppConst.USER_ADMIN.equals(user.getState())){
            roles.add("admin");
        }
        return roles;
    }
}
